<?php
namespace library\Core;

class Config
{

    public static function setBasePath($path)
    {
        return ConfigLoader::setBasePath($path);
    }

    public static $_CONFIG = array();
    public static $PARAMS_CONFIG = NULL;

    public static function loadParamsConfig($configFile)
    {

        self::$PARAMS_CONFIG = ConfigLoader::loadConfig($configFile);
    }

//    public static function getParamsVal($key) {
//        return self::$PARAMS_CONFIG[$key];
//    }

    public static function getParamsVal($name, $key = '')
    {
        $result = array();
        $result = isset(self::$PARAMS_CONFIG[$name]) ? self::$PARAMS_CONFIG[$name] : array(); //如果参数数组存在
        $result = $key != '' ? (isset(self::$PARAMS_CONFIG[$name][$key]) ? self::$PARAMS_CONFIG[$name][$key] : null) : $result; //如果参数key在
        return $result;
    }

    public static $DATABASE_CONFIG = NULL;

    public static function loadDbConfig($configFile)
    {

        self::$DATABASE_CONFIG = ConfigLoader::loadConfig($configFile);
    }

    public static function getDbConfig($dbName)
    {
        return isset(self::$DATABASE_CONFIG[$dbName]) ? self::$DATABASE_CONFIG[$dbName] : NULL;
    }

    public static $SOURCES_CONFIG = NULL;

    public static function loadSourcesConfig($configFile)
    {

        self::$SOURCES_CONFIG = ConfigLoader::loadConfig($configFile);
    }

    //被动加载方式
    public static $MEMCACHE_CONFIG = NULL;
    public static $_MEMCACHE_CONFIG_FILE = NULL;

    public static function loadMemcacheConfig($configFile)
    {

        self::$_MEMCACHE_CONFIG_FILE = $configFile;
    }

    public static function getMemcacheConfig($adapter)
    {

        if (self::$MEMCACHE_CONFIG === NULL) {
            self::$MEMCACHE_CONFIG = ConfigLoader::loadConfig(self::$_MEMCACHE_CONFIG_FILE);
        }
        return isset(self::$MEMCACHE_CONFIG[$adapter]) ? self::$MEMCACHE_CONFIG[$adapter] : NULL;
    }

    public static $REDIS_CONFIG = NULL;
    public static $_REDIS_CONFIG_FILE = NULL;

    public static function loadRedisConfig($configFile)
    {

        self::$_REDIS_CONFIG_FILE = $configFile;
    }

    public static function getRedisConfig($adapter)
    {

        if (self::$REDIS_CONFIG === NULL) {
            self::$REDIS_CONFIG = ConfigLoader::loadConfig(self::$_REDIS_CONFIG_FILE);
        }
        return isset(self::$REDIS_CONFIG[$adapter]) ? self::$REDIS_CONFIG[$adapter] : NULL;
    }

}
